import { categoriesData } from "../../data/category";
Page({
  data: {
    activeKey: 0,
    tags: [],
    activeColor: 'red',
    goods: []
  },
  onLoad() {
    let _tags=[];
    for(let i=0;i<categoriesData.length;i++){
      _tags.push({name:categoriesData[i].name});
    }
    this.setData({tags:_tags});
    this.onSidebarChange();
  },
  onSidebarChange(e) {
    //console.log('onSidebarChange:',e.detail);
    let index;
    if(e)
      index = e.detail;
    else
      index = 0;
    let goods = [];
    let list = categoriesData[index].children;
    let len = list.length+(3-list.length%3);
    for(let i=0;i<len;i++){
      if(i>list.length-1){
        goods.push(null);
      }else{
        goods.push(list[i]);
      }
    }
    this.setData({goods:goods});
  },
  toList(e) {
    wx.navigateTo({
      url: '/pages/goods/search/list/index?kw='+e.currentTarget.dataset.name+"&search=-1",
    })
  },
});